/* GUI CONVERTED from rprsiq03.p (converter v1.75) Tue Aug 22 11:49:20 2000 */
/* rprsiq03.p - PRODUCT LINE RESOURCE LOAD SUMMARY INQUIRY              */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                 */
/* All rights reserved worldwide.  This is an unpublished work.        */
/*F0PN*/ /*V8:ConvertMode=Report                                        */
/* REVISION: 1.0     LAST MODIFIED: 06/16/86    BY: emb                 */
/* REVISION: 4.0     LAST MODIFIED: 06/20/89    BY: emb *A748*          */
/* REVISION: 5.0     LAST MODIFIED: 02/20/90    BY: wug *D017*          */
/* REVISION: 6.0     LAST MODIFIED: 10/23/90    BY: emb *D130*          */
/* REVISION: 6.0     LAST MODIFIED: 02/14/91    BY: ram *D351*          */
/* REVISION: 7.0     LAST MODIFIED: 10/11/91    BY: emb *F024*          */
/* REVISION: 7.3     LAST MODIFIED: 10/23/92    BY: ram *G231*          */
/* Revision: 7.3        Last edit: 11/19/92             By: jcd *G339* */
/* REVISION: 7.3     LAST MODIFIED: 11/10/93    BY: ais *GH07*          */
/* REVISION: 7.4     LAST MODIFIED: 02/13/97    BY: *H0QB*  Russ Witt   */
/* REVISION: 8.6E      LAST MODIFIED: 02/23/98   BY: *L007* A. Rahane   */
/* REVISION: 8.6E      LAST MODIFIED: 05/20/98   BY: *K1Q4* Alfred Tan  */
/* REVISION: 8.6E      LAST MODIFIED: 09/01/98   BY: *L08F* A. Shobha   */
/* REVISION: 8.6E      LAST MODIFIED: 09/17/98   BY: *J2Z1* G.Latha     */
/* REVISION: 8.6E      LAST MODIFIED: 02/17/99   BY: *J3B6* Vivek Gogte */
/* REVISION: 9.1      LAST MODIFIED: 03/24/00    BY: *N08T* Annasaheb Rahane */
/* REVISION: 9.1      LAST MODIFIED: 08/11/00   BY: *N0K5* Arul Victoria   */

         /* DISPLAY TITLE */

/*GUI preprocessor directive settings */
&SCOPED-DEFINE PP_GUI_CONVERT_MODE REPORT

         {mfdtitle.i "b+ "}   /*GH07*/

/* ********** Begin Translatable Strings Definitions ********* */

&SCOPED-DEFINE rprsiq03_p_4 "Month"
/* MaxLen: Comment: */

&SCOPED-DEFINE rprsiq03_p_5 "Day/Week/Month"
/* MaxLen: Comment: */

&SCOPED-DEFINE rprsiq03_p_7 "Months/Column"
/* MaxLen: Comment: */

/* ********** End Translatable Strings Definitions ********* */

/*N0K5* ------------------- BEGIN DELETE ----------------------- *
 *
 * &SCOPED-DEFINE rprsiq03_p_1 "Load          "
 * /* MaxLen: Comment: */
 *
 * &SCOPED-DEFINE rprsiq03_p_2 "Cumulative    "
 * /* MaxLen: Comment: */
 *
 * &SCOPED-DEFINE rprsiq03_p_3 "Over/Under    "
 * /* MaxLen: Comment: */
 *
 * &SCOPED-DEFINE rprsiq03_p_6 "Past    "
 * /* MaxLen: Comment: */
 *
 * &SCOPED-DEFINE rprsiq03_p_8 " LOAD % OF CAPACITY "
 * /* MaxLen: Comment: */
 *
 * /*J2Z1** &SCOPED-DEFINE rprsiq03_p_9 "Press space bar to display graph" */
 * /* MaxLen: Comment: */
 *
 * &SCOPED-DEFINE rprsiq03_p_10 "Capacity      "
 * /* MaxLen: Comment: */
 *
 * &SCOPED-DEFINE rprsiq03_p_11 "Workdays      "
 * /* MaxLen: Comment: */
 *
 *N0K5* ------------------- END   DELETE ----------------------- */

         define variable site like si_site.
         define variable start like pq_start.
         define variable ending like pq_end.
         define variable old_start as date.
         define variable rscde like pq_rsc.
         define variable rscde1 like pq_rsc.
         define variable interval as integer extent 8.
         define variable sdate like rq_start extent 8.
/*H0QB*  define variable load as decimal extent 8 format ">>>>,>>9".  */
/*H0QB*/ define new shared variable load as decimal extent 8 format ">>>>,>>9"
/*H0QB*/                                 no-undo.
/*H0QB*  define variable cap as decimal extent 8 format ">>>>,>>9".   */
/*H0QB*/ define new shared variable cap as decimal extent 8 format ">>>>,>>9"
/*H0QB*/                                 no-undo.
         define variable ovund as decimal extent 8 format "->>>,>>9".
         define variable cum as decimal extent 8 format "->>>,>>9".
         define variable workdays as integer extent 8 format ">>>>,>>9".
         define variable periods as integer extent 8 format ">>>>,>>9".
         define variable det_load as decimal extent 8 format ">>>>,>>9".
         define variable holiday as integer.
         define variable i as integer.
         define variable j as integer.
         define variable qty like pq_qty.
         define variable wostart as integer.
         define variable nonwdays as decimal.
         define variable elapsedays as integer.
         define variable wdays as integer.
         define variable overlap as integer.
         define variable wointerval as integer.
         define variable offset like pq_lt_off.
         define variable ltoff like pq_lt_off.
         define variable ltoffperiod as integer.
         define variable lead as integer.
         define variable dwm as character format "!(1)" label {&rprsiq03_p_5}.
         define variable idays as integer format ">>>>>9"
/*GH07*     label "Per Column".       */
/*GH07*/    label {&rprsiq03_p_7}.
         define variable monthend as integer.
         define variable num_intervals as integer initial 7.
         define variable period as integer.
         define variable prod_start as date.
         define variable prod_end as date.
         define variable more like mfc_logical.

         define new shared variable vq_-ratio as integer extent 7 no-undo.
         define new shared variable vq_-title as character no-undo.
         define new shared variable vq_-period as date extent 14 no-undo.
         define new shared variable vq_-bar-color as character no-undo.
/*H0QB*/ define new shared variable vq_-day-week-month as character no-undo.
         define variable x as integer.

         
/*GUI preprocessor Frame A define */
&SCOPED-DEFINE PP_FRAME_NAME A

FORM /*GUI*/ 
            site
            rscde
            start
            ending
/*GH07*     dwm                      */
            idays
         with frame a no-underline width 80 attr-space THREE-D /*GUI*/.

/*GUI preprocessor Frame A undefine */
&UNDEFINE PP_FRAME_NAME



         /* SET EXTERNAL LABELS */
         setFrameLabels(frame a:handle).

         site = global_site.
/*L08F*/ {wbrp01.i}

         repeat:
            do:
               if start = ? then start = date(month(today),1,year(today)).
               if old_start <> ? then start = old_start.
               if dwm = "" then dwm = "M".
               if idays = 0 or idays = ? then idays = 1.
/*GH07*        display dwm with frame a.          */
/*L08F*/       if c-application-mode <> 'WEB':U then
               update site rscde start ending idays with frame a editing:
                  if frame-field = "site" then do:
                     /* FIND NEXT/PREVIOUS RECORD */
                     {mfnp.i si_mstr site si_site site si_site si_site}
                     if recno <> ? then do:
                        site = si_site.
                        display site with frame a.
                     end.
                  end.
                  else if frame-field = "rscde" then do:
                     /* FIND NEXT/PREVIOUS RECORD */
                     {mfnp.i rs_mstr rscde rs_rsc rscde rs_rsc rs_rsc}
                     if recno <> ? then do:
/*G231*/                site = rs_site.
                        rscde = rs_rsc.
/*G231                  display rscde with frame a. */
/*G231*/                display site rscde with frame a.
                     end.
                  end.
                  else do:
                     status input.
                     readkey.
                     apply lastkey.
                  end.
               end.

/*L08F*/       {wbrp06.i &command = update
                     &fields = "site rscde start ending idays "
                         &frm = "a" }
/*L08F*/     if c-application-mode <> 'WEB':U or
/*L08F*/     ( c-application-mode = 'WEB':U and
/*L08F*/     c-web-request begins 'DATA':U) then do:
/*G231         find rs_mstr where rs_rsc = rscde no-lock no-wait no-error. */
/*G231*/       find rs_mstr where rs_rsc = rscde
/*G231*/       and rs_site = site no-lock no-wait no-error.
               if available rs_mstr then do:
                  rscde = rs_rsc.
                  display rscde with frame a.
               end.

               if day(start) <> 1 then do:
                  start = date(month(start),1,year(start)).
                  display start with frame a.
               end.

               hide frame b.
/*L08F*/     end.

               /* SELECT PRINTER */
               {mfselprt.i "terminal" 80}

            end.
            old_start = start.

            repeat:

               /* COMPUTE START DATES */
               sdate[1] = min(today,old_start).
               {mfcsdate.i}
               display space(15)
/*N0K5*          {&rprsiq03_p_6}    */
/*N0K5*/          getTermLabel("PAST",8)
                  sdate[2 for 6] skip
               with frame b no-labels STREAM-IO /*GUI*/ .
               display
               space(15) sdate[2] - 1 sdate[3] - 1 sdate[4] - 1 sdate[5] - 1
                         sdate[6] - 1 sdate[7] - 1 sdate[8] - 1 skip
               space(15)
               "-------- -------- -------- -------- -------- -------- -------- "
               with frame b no-labels width 80 STREAM-IO /*GUI*/ .

               /* INITIALIZE VARIABLES */
               cap = 0.
               workdays = 0.
               periods = 0.
               load = 0.
               ovund = 0.
               cum = 0.

               /* CALCULATE WORKING DAYS IN EACH INTERVAL */
               {mfcwdays.i site}

               /* CALCULATE CAPACITY IN EACH INTERVAL */
/*G231         {mfccap.i} */
/*G231*/       {mfccap.i site}

               more = no.

               /* CALCULATE LOAD IN EACH PERIOD */
               pause 0 no-message.
               if dev = "terminal" then do:
                  {mfmsg.i 401 1}
                  /* "CALCULATING LOAD" */
               end.
               for each pq_mstr where pq_rsc = rscde and pq_site = site no-lock:
                                
/*GUI*/ {mfguichk.i } /*Replace mfrpchk*/
                     /*G339*/

                  for each pp_plan where pp_prod_line = pq_prod_line
/*J3B6**             and pp_site = pq_site                                 */
/*J3B6**             and (pp_year >= year(pq_start) or pq_start = ?)       */
/*J3B6**             and (pp_year <= year(pq_end) or pq_end = ?) no-lock:  */
/*J3B6*/             and pp_site = pq_site no-lock:

/*J3B6*/             /* CONDITION MODIFIED AS ORACLE CAN ONLY USE <> OR =  */
/*J3B6*/             /* AGAINST NULL VALUES                                */
/*J3B6*/             if pq_start <> ? and pp_year < year(pq_start)  then next.
/*J3B6*/             else
/*J3B6*/             if pq_end <> ? and pp_year > year(pq_end) then next.
                     
/*GUI*/ {mfguichk.i } /*Replace mfrpchk*/
                                /*G339*/

                     /* CALCULATE LOAD FOR A PRODUCT LINE PRODUCTION PLAN */
                     /* INITIALIZE det_load ARRAY */
                     det_load = 0.

                     period_loop:
                     do period = 1 to 12:

                        if pp_prod_fcst[period] <> 0 then do:

                           /* CALCULATE PRODUCT LINE RESOURCE LOAD */
                           {mfpqld.i}
                           if wointerval = num_intervals + 1 then more = yes.

                           /* DISPLAY FORECASTS WHILE CALCULATING LOAD */
                           pause 0 no-message.
                           if dev = "terminal" then do with frame c:
                              /* SET EXTERNAL LABELS */
                              setFrameLabels(frame c:handle).
                              display pq_prod_line pp_year period label {&rprsiq03_p_4}
                                 pp_prod_fcst[period] with frame c STREAM-IO /*GUI*/ .
                           end. /* if dev = "terminal" then */

                        end.
                     end.
                  end.
               end.
               hide frame c no-pause.

               /* DISPLAY WORKDAYS CAPACITY LOAD OVER/UNDER AND CUMULATIVE */

/*N0K5* ------------------- BEGIN DELETE ----------------------- *
 *             display {&rprsiq03_p_11} workdays[1 for 7]
 *             with frame b no-labels.
 *
 *             display {&rprsiq03_p_10} cap[1 for 7] with frame b no-labels.
 *
 *             display {&rprsiq03_p_1} load[1 for 7] with frame b no-labels.
 *N0K5* ------------------- END   DELETE ----------------------- */

/*N0K5* ------------------- BEGIN ADD ----------------------- */
               display
                   getTermLabel("WORKDAYS",14) format "x(14)"
                   workdays[1 for 7]
               with frame b no-labels STREAM-IO /*GUI*/ .

               display
                  getTermLabel("CAPACITY",14) format "x(14)"
                  cap[1 for 7] with frame b no-labels STREAM-IO /*GUI*/ .

               display
                  getTermLabel("LOAD",14) format "x(14)"
                  load[1 for 7] with frame b no-labels STREAM-IO /*GUI*/ .

/*N0K5* ------------------- END   ADD ----------------------- */

               do i = 1 to num_intervals + 1:
                  ovund[i] = cap[i] - load[i].
                  ovund[i] = integer(ovund[i]).
                  cum[i] = ovund[i].
                  if i > 1 then cum[i] = cum[i] + cum[i - 1].
               end.

/*N0K5* ------------------- BEGIN DELETE ----------------------- *
 *             display {&rprsiq03_p_3} ovund[1 for 7] with frame b no-labels.
 *
 *             display {&rprsiq03_p_2} cum[1 for 7] with frame b no-labels.
 *
 *N0K5* ------------------- END   DELETE ----------------------- */

/*N0K5* ------------------- BEGIN ADD ----------------------- */
               display
                  getTermLabel("OVER/UNDER",14) format "x(14)"
                  ovund[1 for 7] with frame b no-labels STREAM-IO /*GUI*/ .

               display
                  getTermLabel("CUMULATIVE",14) format "x(14)"
                  cum[1 for 7] with frame b no-labels STREAM-IO /*GUI*/ .

/*N0K5* ------------------- END   ADD ----------------------- */

/*L08F               if path = "terminal" then repeat: */
               if path = "terminal" and
/*L08F*/       c-application-mode <> 'WEB':U then repeat:

/*J2Z1*/          /* HARDCODED MESSAGE HAS BEEN REPLACED */
/*J2Z1**          message {&rprsiq03_p_9}. */
/*J2Z1*/          {mfmsg.i 1143 1}
                  readkey.
                  if lastkey = 32 then do:

/*H0QB*/             vq_-day-week-month = dwm.
                     do x = 1 to 7:
            /*          load[x] = random(0,200). */
                        vq_-period[x] = sdate[x].
                        vq_-period[x + 7] = sdate[x + 1] - 1.
/*H0QB*                 vq_-ratio[x] = load[x] / cap[x] * 100.    */
/*H0QB*/                vq_-ratio[x] = truncate(load[x],0) / truncate(cap[x],0)
/*H0QB*/                               * 100.

                     end.

                     /* ASSIGN THE COLORS */
                     assign vq_-bar-color = if opsys eq "msdos"
                                            and terminal eq "co80"
                                            then "white/red"
                                            else "message".

/*N0K5* ------------------- BEGIN DELETE ----------------------- *
 *                   /* ASSIGN THE TITLE */
 *                   assign vq_-title = {&rprsiq03_p_8}.
 *N0K5* ------------------- END   DELETE ----------------------- */

/*N0K5* ------------------- BEGIN ADD ----------------------- */
                     /* ASSIGN THE TITLE */
                     assign
                      vq_-title = " " +
                      caps(getTermLabel("LOAD_PERCENT_OF_CAPACITY",76)) +  " ".
/*N0K5* ------------------- END   ADD ----------------------- */

                     /* NOTE LEADING/TRAILING BLANKS */
/*H0QB*/ /*V8+*/
/*H0QB*/      
                     {gprun.i ""gpgraphw.p""}      

                  end.
                  else leave.
               end.

               {mfsumtrl.i}
               status default.
            end.

            {mfreset.i}
/*GUI*/ {mfgrptrm.i} /*Report-to-Window*/


            pause 0 no-message.
            {mfmsg.i 8 1}
         end.
/*L08F*/ {wbrp04.i &frame-spec=a}
